#include "sbi.h"

struct sbiret sbi_extcall(enum EID EID, unsigned long FID, unsigned long a0,
                          unsigned long a1, unsigned long a2) {
  register unsigned long _a0 asm("a0") = (unsigned long)(a0);
  register unsigned long _a1 asm("a1") = (unsigned long)(a1);
  register unsigned long _a2 asm("a2") = (unsigned long)(a2);
  register unsigned long _a7 asm("a7") = (unsigned long)(EID);
  register unsigned long _a6 asm("a6") = (unsigned long)(FID);
  asm volatile("ecall"
               : "+r"(_a0), "+r"(_a1)
               : "r"(_a2), "r"(_a6), "r"(_a7)
               : "memory");
  struct sbiret ret = {_a0, _a1};
  return ret;
}
